<!--
 * @Author: jinye.zhang
 * @Version: 1.0.0
 * @LastEditors: jinye
 * @Description: new file
-->
<script>
import { commonShare } from "@/utils/commonShare.js";
import { authorization } from "@/utils/login.js";
import { userStatisticsOrder } from "@/api/user";
import { artworksTypeAllList, posterList, userIncome } from "@/api/applet";
export default {
  onLaunch: function (options) {
    uni.setStorageSync("firstUrl", location.href.split("#")[0]);
    console.log("options>>>>>>>", options);
    if (options && options.path === "pages/index/index" && options.query.id) {
      uni.setStorageSync("businessId", options.query.id);
    } else if (
      options &&
      (options.path === "pages/merchant/merchant" ||
        options.path === "pages/publish/makeWallpaper" ||
        options.path === "pages/publish/nationalDayAvatar" ||
        options.path === "pages/newEdit/newEdit" ||
        options.path === "pages/commonAlbumPublish/index") &&
      options.query.id
    ) {
      if (options.query.id.indexOf("@") > -1) {
        let querys = options.query.id.split("@");
        uni.setStorageSync("businessId", querys[0]);
      } else {
        uni.setStorageSync("businessId", options.query.id);
      }
      uni.setStorageSync("businessId", options.query.id);
      return;
    }
    if(options && options.query && options.query.path == 'orderList'){
      uni.navigateTo({ url: "/pages/orderList/order" });
    }

    // this.getWechatConfigFn();
    // 如果是创建模板的话，就不走登录逻辑
    if (
      options &&
      options.query &&
      options.query.createTemplate &&
      options.query.createTemplate === "pc"
    ) {
      return;
    }
    // 授权登录
    authorization({
      source_code: options.query.source_code,
      code: options.query.code,
    }).then((result) => {
      console.log(345235, "授权");
      this.getUserStatisticsOrder();
      this.getUserArtworksIncome();
    });
    if (options.query.id.indexOf("@") > -1) {
      let querys = options.query.id.split("@");
      if (querys[1] === "merchant") {
        uni.navigateTo({
          url: `/pages/merchant/merchant`,
        });
      }
    }
    // 获取作品
    this.getArtworksTypeAllList();
    this.getFindAllBannerListByType();
    commonShare();

    uni.getSystemInfo({
      success: (res) => {
        let bottomHeight = res.safeArea ? res.safeArea.bottom : 640;
        this.$store.dispatch(
          "setsafeAreaBottomHeight",
          res.screenHeight - bottomHeight + 20
        );
      },
      fail(err) {
        console.log(err);
      },
    });
  },
  onShow: function (options) {
    uni.setStorageSync("source", options.scene);
    // console.log('App Show')
  },
  onHide: function (options) {
    // console.log('App Hide')
  },
  methods: {
    // 获取用户统计信息
    getUserStatisticsOrder() {
      userStatisticsOrder().then((result) => {
        if (result && result.code === 200) {
          this.$store.dispatch("setUserStatistics", result.data);
        }
      });
    },

    // 获取作品预估收益信息信息
    async getUserArtworksIncome() {
      let that = this;
      userIncome({
        platform_type: "mp-toutiao",
      }).then((result) => {
        uni.hideLoading();
        if (result.code === 200 && result.data) {
          this.$store.dispatch("setUserIncomeData", result.data);
        }
      });
    },

    // 获取作品类型
    getArtworksTypeAllList() {
      artworksTypeAllList().then((result) => {
        if (result && result.data) {
          result.data.forEach((item) => {
            item.checked = false;
            item.disabled = false;
          });
          this.$store.dispatch("setArtworksAllListData", result.data);
        }
      });
    },

    // 获取海报
    getFindAllBannerListByType() {
      posterList({
        type: "1",
      }).then((result) => {
        if (result && result.code === 200) {
          this.$store.dispatch("setPostList", result.data);
        }
      });
    },
  },
};
</script>

<style lang="scss">
@import "@/static/iconfont/iconfont.css";
/*每个页面公共css */
@import "uview-ui/index.scss";

/* #ifdef H5 */
html,
body {
  margin: auto !important;
  background: #f5f5f5;
}
.uni-tabbar {
  max-width: 430px;
  margin: auto;
}
/* #endif */

.huiju-iconfont {
  font-size: 28rpx;
}

.flex {
  display: flex;
}

.jc {
  justify-content: center;
}

.jb {
  justify-content: space-between;
}

.je {
  justify-content: flex-end;
}

.ac {
  align-items: center;
}

.fw {
  flex-wrap: wrap;
}

.fc {
  flex-direction: column;
}

/* 布局 */
.row {
  /* #ifndef APP-PLUS-NVUE */
  display: flex;
  /* #endif */
  flex-direction: row;
  align-items: center;
  flex-wrap: wrap;
}

.column {
  /* #ifndef APP-PLUS-NVUE */
  display: flex;
  /* #endif */
  flex-direction: column;
}

.center {
  /* #ifndef APP-PLUS-NVUE */
  display: flex;
  /* #endif */
  align-items: center;
  justify-content: center;
}

.fill {
  flex: 1;
}

.default-box-shadow {
  box-shadow: 0rpx 8rpx 10rpx 2rpx #eeeef3;
  border-radius: 4rpx;
}

.clear-padding {
  padding: 0;
}

.text-overflow {
  overflow: hidden; // 超出一行文字自动隐藏
  text-overflow: ellipsis; // 文字隐藏后添加省略号
  white-space: nowrap; // 强制不换行
}

.loading-content {
  width: 100%;
  height: 200rpx;
  text-align: center;
  padding: 40rpx;
}

.loading-content-text {
  color: $uni-text-color-grey;
  font-size: 28rpx;
  padding-top: 24rpx;
}

.back-top {
  position: fixed;
  width: 100rpx;
  height: 100rpx;
  bottom: 100rpx;
  right: 50rpx;
  border-radius: 50%;
  background: url(https://ai-avatar-qiniu.jiaxianghui.cn/backtop.png) no-repeat
    center / 80%;
  background-color: rgba(255, 255, 255, 1);
}

.mb-20 {
  margin-bottom: 20rpx;
}

.ml-6 {
  margin-bottom: 6rpx;
}

.mtb-20 {
  margin-bottom: 20rpx;
  padding-top: 20rpx;
}

.flex-item {
  flex: 1;
}

.box-shadow {
  box-shadow: #eeeef3 0rpx 0rpx 20rpx;
}

.fontsize16 {
  font-size: 32rpx;
}

.fontsize14 {
  font-size: 28rpx;
}

.text-right {
  text-align: right;
}

.color888 {
  color: #888;
}

.justify-content-end {
  justify-content: flex-end;
}

.back-top {
  position: fixed;
  width: 100rpx;
  height: 100rpx;
  bottom: 100rpx;
  right: 50rpx;
  border-radius: 50%;
  background: url(https://ai-avatar-qiniu.tsgzs.com/backtop.png) no-repeat
    center / 80%;
  background-color: rgba(255, 255, 255, 1);
}

.feedback-icon {
  width: 50rpx;
  background: $uni-color-primary;
  color: #fff;
  position: fixed;
  left: 0;
  top: 240rpx;
  writing-mode: lr-tb;
  text-align: center;
  font-size: 28rpx;
  padding: 15rpx 0;
  border-radius: 0 20rpx 20rpx 0;
}
</style>